API Documentation
Public Member Functions | List of all members
nkAstraeus::lua::nkTasksWrap::LuaTask Class Referencefinal

Overrides a nkTasks::Task to be able to use it within a Lua environment. More...

Inheritance diagram for nkAstraeus::lua::nkTasksWrap::LuaTask:
nkTasks::Task

Public Member Functions

UbyteArrayData * getInputBinaryData () const
 
UbyteArrayData * getOutputBinaryData () const
 
void setWorkFuncReference (const nkScripts::ScriptObjectReference &reference)
 
void setInitScript (nkScripts::Script *script)
 
void setInputBinaryData (UbyteArrayData *data, const nkScripts::ScriptObjectReference &ref)
 
void setOutputBinaryData (UbyteArrayData *data)
 
void addInputUserData (void *ptr, const nkMemory::StringView &typeName, bool owner)
 
void addOutputUserData (void *ptr, const nkMemory::StringView &typeName, bool owner)
 
const UserDataHoldergetInputUserData (unsigned int index) const
 
const UserDataHoldergetOutputUserData (unsigned int index) const
 
- Public Member Functions inherited from nkTasks::Task
 Task ()
 
virtual ~Task ()
 
ThreadgetParentThread () const
 
TASK_RESULT getWorkResult () const
 
void setParentThread (Thread *thread)
 
void setWorkResult (TASK_RESULT result)
 
virtual TASK_RESULT onWork ()=0
 
virtual void onWorkDone ()=0
 
virtual void onSuccess ()=0
 
virtual void onFail ()=0
 
virtual void onAbort ()=0
 

Detailed Description

Overrides a nkTasks::Task to be able to use it within a Lua environment.

Symbols are not exported, this class is not meant to be used as is from the C++ code, but rather from the scripting environment. Documented functions are available in the environment through TaskWrapper.

Within Lua, threads are not allowed. See LuaThread for more details. As such, memory management within tasks has to be done cautiously. Be sure to manage correctly user data ownership when passing them around. Lua objects need to be serialized before being communicated. Typically :

local d = {} ;
d.str = "Hey" ;
d.obj = nkGraphics.Vector.new() ;
task.inputBinaryData = nkScripts.serialize(d) ;

If ownership of user data has to be passed around, use serializeForwardOwnership().

Member Function Documentation

◆ getInputBinaryData()

UbyteArrayData* nkAstraeus::lua::nkTasksWrap::LuaTask::getInputBinaryData ( ) const
Returns
The binary data set as input for the task.

◆ getOutputBinaryData()

UbyteArrayData* nkAstraeus::lua::nkTasksWrap::LuaTask::getOutputBinaryData ( ) const
Returns
The binary data set as output for the task.

◆ setWorkFuncReference()

void nkAstraeus::lua::nkTasksWrap::LuaTask::setWorkFuncReference ( const nkScripts::ScriptObjectReference reference)

Sets the work function to use, through a reference within the calling thread. This function will be executed when the task is submitted for work.

Parameters
referenceThe reference to the function.

◆ setInitScript()

void nkAstraeus::lua::nkTasksWrap::LuaTask::setInitScript ( nkScripts::Script script)

Sets the script to run once when launching the task. This will be run before the work function. Such a script can be used to set up some variables within the work thread before working on it.

Parameters
scriptThe script to execute as an initialization step.

◆ setInputBinaryData()

void nkAstraeus::lua::nkTasksWrap::LuaTask::setInputBinaryData ( UbyteArrayData *  data,
const nkScripts::ScriptObjectReference ref 
)

Allows to set binary data, marking it as input. Binary data will be available in the work thread, and is supposed to be alive in the calling thread.

Parameters
dataThe data to use as input.
refThe reference of the buffer, to prevent garbage collection.

◆ setOutputBinaryData()

void nkAstraeus::lua::nkTasksWrap::LuaTask::setOutputBinaryData ( UbyteArrayData *  data)

Allows to set binary data, marking it as output. The data will be copied so that a reference can be kept alive within the calling thread.

Parameters
dataThe data to link as output data.

◆ addInputUserData()

void nkAstraeus::lua::nkTasksWrap::LuaTask::addInputUserData ( void *  ptr,
const nkMemory::StringView typeName,
bool  owner 
)

Adds a user data as an input for the task.

Parameters
ptrThe user data pointer.
typeNameThe user type name of the data.
ownerWhether the script environment retrieving the data should become owner of the data (true) or not (false).

◆ addOutputUserData()

void nkAstraeus::lua::nkTasksWrap::LuaTask::addOutputUserData ( void *  ptr,
const nkMemory::StringView typeName,
bool  owner 
)

Adds a user data as an output for the task.

Parameters
ptrThe user data pointer.
typeNameThe user type name of the data.
ownerWhether the script environment retrieving the data should become owner of the data (true) or not (false).

◆ getInputUserData()

const UserDataHolder* nkAstraeus::lua::nkTasksWrap::LuaTask::getInputUserData ( unsigned int  index) const
Parameters
indexThe index of the user data to retrieve.
Returns
The user data requested.

◆ getOutputUserData()

const UserDataHolder* nkAstraeus::lua::nkTasksWrap::LuaTask::getOutputUserData ( unsigned int  index) const
Parameters
indexThe index of the user data to retrieve.
Returns
The user data requested.

The documentation for this class was generated from the following file: